import java.util.Vector;

/**
 * A class that handles the commands to be sent to the server.
 * @author bjorn, kristian
 * 
 */
public class ServerCommand {
	
	private String name;
	private Vector<CommandParameter> values;
	
	/**
	 * Creates a new empty ServerCommand.
	 */
	public ServerCommand() {
		name = null;
		values = new Vector<CommandParameter>();
	}
	
	/**
	 * Creates a ServerCommand with command name name and parameter cp.
	 * @param name
	 * @param cp
	 */
	public ServerCommand(String name, CommandParameter cp) {
		this.name = name;
		this.values = new Vector<CommandParameter>();
		this.values.addElement(cp);
	}
	
	/**
	 * Creates a ServerCommand with command name name and parameters cps.
	 * @param name
	 * @param cps
	 */
	public ServerCommand(String name, Vector<CommandParameter> cps) {
		this.name = name;
		this.values = new Vector<CommandParameter>();
		for(Integer i = 0; i < cps.size(); i++) {
			this.values.addElement(cps.elementAt(i));
		}
	}
	
	/**
	 * Returns the number of parameters in the ServerCommand.
	 * @return The number of parameters.
	 */
	public Integer commandParameterCount() {
		return values.size();
	}
	
	/**
	 * Adds the parameter cp to the list of parameters of the ServerCommand.
	 * @param cp
	 */
	public void addCommandParameter(CommandParameter cp) {
		this.values.addElement(cp);
	}
	
	/**
	 * Returns the i:th parameter of the ServerCommand.
	 * @param i
	 * @return The i:th parameter.
	 */
	public CommandParameter getCommandParameter(Integer i) {
		return values.elementAt(i);
	}
	
	/**
	 * Returns the value of the parameter with name paramName.
	 * @param paramName
	 * @return The value of the parameter. If the parameter name doesn't exists, 0 is returned.
	 */
	public Integer getValueOfParameter(String paramName) {
		for(Integer i = 0; i < this.values.size(); i++) {
			if(this.values.elementAt(i).getName().equals(paramName)) {
				return this.values.elementAt(i).getValue();
			}
		}
		return 0;
	}
	
	/**
	 * Returns the name of the ServerCommand.
	 * @return The name of the ServerCommand.
	 */
	public String getName() {
		return this.name;
	}
	
	/**
	 * Sets the name of the ServerCommand to name.
	 * @param name
	 */
	public void SetName(String name) {
		this.name = name;
	}
	
	/**
	 * Evaluates if the server command is of type move.
	 * @return True if the command type is move, false otherwise.
	 */
	public boolean isMove() {
		if(name.equals("move"))
			return true;
		else
			return false;
	}

	/**
	 * Evaluates if the server command is of type G2close.
	 * @return True if the command type is G2close, false otherwise.
	 */
	public boolean isClose() {
		if(name.equals("G2close"))
			return true;
		else
			return false;
	}
	
	/**
	 * Evaluates if the server command is of type G2close.
	 * @return True if the command type is G2close, false otherwise.
	 */
	public boolean isAuto() {
		if(name.equals("G2autoMode"))
			return true;
		else
			return false;
	}

	/**
	 * Evaluates if the server command is of type rotate.
	 * @return True if the command type is rotate, false otherwise.
	 */
	public boolean isRotate() {
		if(name.equals("rotate"))
			return true;
		else
			return false;
	}

	/**
	 * Evaluates if the server command is of type scan.
	 * @return True if the command type is scan, false otherwise.
	 */
	public boolean isScan() {
		if(name.equals("scan"))
			return true;
		else
			return false;
	}

	/**
	 * Evaluates if the server command is of type reboot.
	 * @return True if the command type is reboot, false otherwise.
	 */
	public boolean isReboot() {
		if(name.equals("reboot"))
			return true;
		else
			return false;
	}
	
	
}
